<?php

namespace LowCode\Traits;

trait HasElementEvents
{
    /**
     * 鼠标单击事件
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onClick(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("click",jsFn($event, $id), $modifiers);
    }

    /**
     * 鼠标双击事件
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDblClick(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dblclick",jsFn($event, $id), $modifiers);
    }

    /**
     * 当按下鼠标按钮时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMousedown(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mousedown",jsFn($event, $id), $modifiers);
    }

    /**
     * 当鼠标指针移动时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMousemove(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mousemove",jsFn($event, $id), $modifiers);
    }

    /**
     * 当鼠标指针移入元素时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMouseenter(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mouseenter",jsFn($event, $id), $modifiers);
    }

    /**
     * 当鼠标指针移出元素时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMouseout(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mouseout",jsFn($event, $id), $modifiers);
    }

    /**
     * 当鼠标指针移至元素之上时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMouseover(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mouseover",jsFn($event, $id), $modifiers);
    }

    /**
     * 当松开鼠标按钮时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMouseup(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mouseup",jsFn($event, $id), $modifiers);
    }

    /**
     * 当按下按键时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onKeydown(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("keydown",jsFn($event, $id), $modifiers);
    }

    /**
     * 当按下并松开按键时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onKeypress(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("keypress",jsFn($event, $id), $modifiers);
    }

    /**
     * 当松开按键时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onKeyup(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("keyup",jsFn($event, $id), $modifiers);
    }

    /**
     * 当滚动元素的滚动条时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onScroll(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("scroll",jsFn($event, $id), $modifiers);
    }

    /**
     * 当转动鼠标滚轮时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onMousewheel(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("mousewheel",jsFn($event, $id), $modifiers);
    }

    /**
     * 当拖动元素时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDrag(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("drag",jsFn($event, $id), $modifiers);
    }

    /**
     * 当拖动操作结束时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDragend(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dragend",jsFn($event, $id), $modifiers);
    }

    /**
     * 当元素被拖动至有效的拖放目标时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDragenter(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dragenter",jsFn($event, $id), $modifiers);
    }

    /**
     * 当元素离开有效拖放目标时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDragleave(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dragleave",jsFn($event, $id), $modifiers);
    }

    /**
     * 当元素被拖动至有效拖放目标上方时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDragover(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dragover",jsFn($event, $id), $modifiers);
    }

    /**
     * 当拖动操作开始时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDragstart(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("dragstart",jsFn($event, $id), $modifiers);
    }

    /**
     * 当被拖动元素正在被拖放时运行脚本
     * @param string $event ()=>{}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onDrop(string $event, string $id = null, array $modifiers = []): static
    {
        return $this->event("drop",jsFn($event, $id), $modifiers);
    }


}
